package cn.tedu.stream.transformation

import org.apache.flink.streaming.api.scala.{DataStream, SplitStream, StreamExecutionEnvironment}

/**
 * @author Amos
 * @date 2022/5/22
 */

object StreamSplitAndSelectDemo {
  def main(args: Array[String]): Unit = {
    val env = StreamExecutionEnvironment.getExecutionEnvironment
    import org.apache.flink.api.scala._
    val source: DataStream[Int] = env.fromElements(1, 2, 3, 4, 5, 6)

    // 数据的分流
    val splitStream: SplitStream[Int] = source.split(x => {
      // 通过模式匹配完成操作
      x % 2 match {
        case 0 => List("even")
        case 1 => List("odd")
      }
    })

    // 获取分流的数据
    val result: DataStream[Int] = splitStream.select("even")

    result.print()
    env.execute()

  }

}
